/**
 * 深度拷贝
 * @param obj
 * @returns {*[]}
 */
export function deepCopy(obj) {
    const res = obj && obj.constructor === Array ? [] : {};
    for (let key in obj) {
        const val = obj[key];
        if (val && typeof val === 'object') {
            res[key] = deepCopy(val);
        } else {
            res[key] = val;
        }
    }
    return res;
}

/**
 * 判断对象是否为空
 * @param obj
 * @returns {boolean}
 */
export function isEmpty(obj) {
    for (let key in obj) {
        return false;
    }
    return true;
}

/**
 * 获取所有类型数据
 * @returns {({}|number|string|boolean|(function())|RegExp|Date|Set<any>)[]}
 */
function getAllTypeData() {
    return [
        {},
        10,
        'hello',
        true,
        function(){},
        null,
        undefined,
        NaN,
        /123/g,
        new Date(),
        new Set(),
        new Map(),
        Symbol(1),
        [],
        document,
        window
    ];
}

/**
 * 检测所有数据的类型
 * @param checkFn 检测方法
 * @returns {{}}
 */
function checkAllTypeData(checkFn) {
    const arr = getAllTypeData();
    const obj = {};
    arr.forEach((item) => {
        const type = checkFn(item);
        if(obj[type]) {
            obj[type].push(item);
        } else {
            obj[type] = [item];
        }
    });
    return obj;
}